<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #outer {
      width: 300px;
      height: 300px;
      background-color: red;
    }
    #inner {
      width: 200px;
      height: 200px;
      background-color: blue;
    }
  </style>
</head>
<body>
  <div id="outer">
    <div id="inner"></div>
  </div>

  <script>

    /* 
      有嵌套的元素，父级和子级都有同一个事件类型，执行子级，父级也会被同时执行，叫做事件冒泡
    
    */
    var outer = document.getElementById('outer')
    var inner = document.getElementById('inner')

    document.body.addEventListener('click', function () {
      console.log('body')
    })

    outer.addEventListener('click', function (ev) {
      console.log('outer')
      ev.stopPropagation()
    })

    // 事件驱动函数中的第一个参数叫做事件对象
    inner.addEventListener('click', function (ev) {
      console.log('inner')
      ev.stopPropagation()
    })

    /* 
      ev.stopPropagation()方法，表示阻止事件冒泡
    
    */


   
  </script>
</body>
</html>